package com.nameless.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nameless.entity.Coupon;
import com.nameless.entity.CouponType;
import com.nameless.service.CouponService;
import com.nameless.service.CouponTypeService;
import com.nameless.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * -*- coding:utf-8 -*-
 *
 * @author 太阳偷渡青山
 * @software IntelliJ IDEA
 * @date 2023/02/27 9:49
 * @Description
 */
@RestController
@Api("优惠劵类型api信息操作接口")
@Slf4j
@RequestMapping("/coupon/api/couponType")
public class ApiTypeCouponController {

    @Autowired
    private CouponTypeService couponTypeService;

    @GetMapping("findAll")
    @ApiOperation(value = "查询全部")
    public Result<List<CouponType>> findAll(){
        return Result.success("查询成功",couponTypeService.list());
    }

    @GetMapping("{id}")
    @ApiOperation(value = "根据id查询单个信息")
    public Result<CouponType> getOne(@PathVariable Long id){
        CouponType byId = couponTypeService.getById(id);
        return Result.success("id为："+id+"的优惠劵查询成功",byId);
    }

    @DeleteMapping
    @ApiOperation(value = "删除多个信息")
    @ApiImplicitParam(name = "idList",value = "需要删除的医院配置id集合")
    public Result<String> delete(@RequestBody List<Integer> idList){
        log.info("idList = {}",idList);
        boolean b = couponTypeService.removeByIds(idList);
        return b?Result.success("删除成功"):Result.error("删除失败");
    }

    @PostMapping
    @ApiOperation(value = "添加信息")
    public Result<String> addCustomer(@RequestBody CouponType coupon){
        boolean save = couponTypeService.save(coupon);
        return save?Result.success("添加成功"):Result.error("添加失败");
    }

    @PutMapping
    @ApiOperation(value = "修改客户信息")
    public Result<String> editCustomer(@RequestBody CouponType coupon){
        boolean save = couponTypeService.updateById(coupon);
        return save?Result.success("修改成功"):Result.error("修改失败");
    }
}
